package server;

import java.util.HashSet;
import java.util.Set;
import java.util.TimerTask;

public class GameTimerTask extends TimerTask {

	Set<GameTimerObserver> observers = new HashSet<GameTimerObserver>(1);
	int tickCount = 0;
	
	
	public GameTimerTask() {
		super();
	}
	
	
	public void attach(GameTimerObserver o) {
		observers.add(o);
	}
	
	
	public void detach(GameTimerObserver o) {
		observers.remove(o);
	}
	
	
	private void notifyObservers() {
		for (GameTimerObserver o : observers) {
			o.timerTick(tickCount);
		}
	}

	
	@Override
	public void run() {
		tickCount++;
		notifyObservers();
	}
	
	
	public void reset() {
		tickCount = 0;
	}
	
	public int getTickCount() {
		return tickCount;
	}
	
}
